# config_loader.py
import yaml
import torch
import pandas as pd



class Config:
    def __init__(self, yaml_path="./configs/config.yaml"):
        with open(yaml_path, "r") as f:
            cfg = yaml.safe_load(f)

        self.env = cfg["env"]
        self.patchtst = cfg["patchtst"]
        self.agent = cfg["agent"]

        self.agent["device"] = torch.device(
            self.agent["device"] if torch.cuda.is_available() else "cpu"
        )

        self.env["price_array"] = pd.read_csv(self.env["price_file_path"]).to_numpy()
        self.env["tech_array"] = pd.read_csv(self.env["tech_file_path"]).to_numpy()
        self.env["if_train"] = self.env["if_train"]
        self.env["initial_future"] = (
            None if self.env["initial_future"] == "None" else self.env["initial_future"]
        )
        self.env["reward_scaling"] = eval(self.env["reward_scaling"])



        self.patchtst["seq_len"] = self.env["window"]
        self.patchtst["device"] = torch.device(
            self.patchtst["device"] if torch.cuda.is_available() else "cpu"
        )
        self.patchtst["tech_num"] = self.env["tech_array"].shape[1]// self.env["price_array"].shape[1]
